//
//  WBDBManager.swift
//  SainMicroblog
//
//  Created by chenxinju on 16/5/18.
//  Copyright © 2016年 chenxinju-a2. All rights reserved.
//

import Foundation
import FMDB

class WBDBManager {
    
 //创建单例 因为在其他地方需要使用数据缓存的地方很多需要
    static let shareInstance:WBDBManager = WBDBManager()
    
    let queue: FMDatabaseQueue
    
   private init() {
    
let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).last! as NSString
    print(path)
    //拼接路径
    let dbPath = path.stringByAppendingPathComponent("weibo.db")

     queue = FMDatabaseQueue(path: dbPath)
    
    createTable() //创建表格和请求

    }
    private func  createTable() {
    
        let sql =  "CREATE TABLE IF NOT EXISTS 'T_Status' (\n" +
            "'status_id' integer NOT NULL,\n" +
            "'status' text NOT NULL,\n" +
            "'user_id' integer NOT NULL,\n" +
            "'createDate' text NOT NULL DEFAULT (datetime('now', 'localtime'))," +
            "PRIMARY KEY('status_id')\n" +
        ");"
        print(sql)
        
      queue.inDatabase { (db) -> Void in
    
        db.executeUpdate(sql, withArgumentsInArray: nil)
        }
    }
}


